<%@page import="java.util.ArrayList"%>
<%@page import="cn.jhc.bean.NewsBean"%>
<%@page import="cn.jhc.dao.ConnectionFactory"%>
<%@page import="cn.jhc.dao.NewsDAO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="./css/news.css"></link>
<style>
* {
	border: 0;
}
</style>
<title>校园新闻</title>
</head>
<body>
	<%
		int CurrentPage = 1;
		int intPageCount;
		if (request.getParameter("page") != null)
			CurrentPage = Integer.parseInt(request.getParameter("page"));
		if (CurrentPage < 1)
			CurrentPage = 1;
	%>
	<div id="wrapper">
		<jsp:include page="./header.jsp"></jsp:include>
		<%
			ArrayList<NewsBean> list = new ArrayList<NewsBean>();
			NewsDAO dao = new NewsDAO();
			dao.setCon(ConnectionFactory.getConnection());
			list = dao.getAllNews(CurrentPage);
			request.setAttribute("news", list);
		%>
		<div id="topall">
			<div id="toptitle">主题</div>
			<div id=toptime>时间</div>
			<div id=topname></div>
		</div>
		<%
			NewsDAO dao2 = new NewsDAO();
			dao2.setCon(ConnectionFactory.getConnection());
			intPageCount = dao2.getCount();
			if (CurrentPage > intPageCount)
				CurrentPage = intPageCount;
		%>
		<c:forEach items="${requestScope.news}" var="news">
			<div id="news">
				<div id="text">
					<a href="newscontext.jsp?id=${news.id}">${news.title}</a>
				</div>
				<div id="date">
					<a>${news.date}</a>
				</div>
			</div>
		</c:forEach>
		<div align="right">
			<a>第<%=CurrentPage%>页 共<%=intPageCount%>页
			</a> <a href="news.jsp?page=<%=1%>">首页</a>
			<%
				if (CurrentPage > 1) {
			%>
			<a href="news.jsp?page=<%=CurrentPage - 1%>">上一页</a>
			<%
				} else {
			%>
			上一页
			<%
				}
			%>
			<%
				if (CurrentPage >= intPageCount) {
			%>
			下一页
			<%
				} else {
			%>
			<a href="news.jsp?page=<%=CurrentPage + 1%>">下一页</a>
			<%
				}
			%>
			<a href="news.jsp?page=<%=intPageCount%>">末页</a>
		</div>
	</div>
</body>
</html>
